package net.skyedu.service;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.skyedu.bean.BasGrade;
import net.skyedu.bean.SysCourse;
import net.skyedu.dao.DaoSupport;

public class InitQuery extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public InitQuery() {
		super();
	}

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		doPost(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		DaoSupport ds = new DaoSupport();
		
//		List<BasTerm> terli = ds.searchTerm();
//		List<BasSubject> subli = ds.searchSubject();
		List<BasGrade> grali = ds.searchGrade();
		
//		request.setAttribute("terli", terli);
//		request.setAttribute("subli", subli);
		request.setAttribute("grali", grali);
		String ID = request.getParameter("id");
		if(ID != null){
			SysCourse sc = ds.findCourse(Integer.parseInt(ID));
			request.setAttribute("sc", sc);
			request.getRequestDispatcher("upcourse.jsp").forward(request, response);
		}else{
			request.getRequestDispatcher("syscourse.jsp").forward(request, response);
		}
		
	}

	public void init() throws ServletException {}

}
